/*
* 解析url参数
* ?id=1&name=a
* return Object {id:1,name:a}
* */
export function urlParse () {
  let url = window.location.search
  let obj = {}
  let reg = /[?&][^?&]+=[^?&]+/g
  let arr = url.match(reg)
  // ['?id=1','&name=a']
  if (arr) {
    arr.forEach((item) => {
      // substring 去 ?& ；split 根据= 分割字符串为数组
      let tempArr = item.substring(1).split('=')
      // ['id','1','name','a']
      let key = decodeURIComponent(tempArr[0])
      let val = decodeURIComponent(tempArr[1])
      obj[key] = val
    })
  }
  return obj
}
